package com.huike.pmps.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.huike.pmps.dao.AreasDao;
import com.huike.pmps.model.entity.Areas;
import com.huike.pmps.model.vo.Result;
import com.huike.pmps.service.AreasService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 作者：谌贵斌(黑桃K)
 * 日期: 2888-08-08
 * 老师QQ: 272488352
 * 官方QQ交流群: 377748272
 * 刀客程序员官网：http://www.daoke360.com
 * 刀客程序员淘宝旗舰店：https://daoke360.taobao.com/
 */
@Service
public class AreasServiceImpl implements AreasService {
    @Autowired
    AreasDao areasDao;

    @Override
    public Result selectByCondition(String cityId) {
        QueryWrapper<Areas> queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotBlank(cityId)) {
            queryWrapper.eq("city_id", cityId);
        }
        return Result.success( areasDao.selectList(queryWrapper));
    }

    @Override
    public Areas selectByAreaId(String areaId) {
        QueryWrapper<Areas> queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotBlank(areaId)) {
            queryWrapper.eq("area_id", areaId);
        }
        return areasDao.selectOne(queryWrapper);
    }

    @Override
    public Areas selectOne(String cityId, String areaName) {
        QueryWrapper<Areas> queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotBlank(cityId)) {
            queryWrapper.eq("city_id", cityId);
        }
        if (StringUtils.isNotBlank(areaName)) {
            queryWrapper.like("area", areaName);
        }
        return areasDao.selectOne(queryWrapper);
    }
}
